package tech.aistar.corejava.day08.demo;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/7/24 0024
 */
public class TestVehicle {
    public static void main(String[] args) {
        Vehicle car = new Car();
        Vehicle plane = new Plane();
        System.out.println(car instanceof ICheckSpeed);//true
        System.out.println(plane instanceof ICheckSpeed);//false

        Vehicle[] vehicles = new Vehicle[2];

        vehicles[0] = car;
        vehicles[1] = plane;

        //遍历数组
        for (Vehicle v:vehicles){
            //针对car需要速度的检测 - 不能超速 - 不能超过100

            //当car的速度超过100那么就显示超速
            //如果plane,无需检测速度

//            if(v.getSpeed()>100){
//                System.out.println("超速!");
//            }else{
//                System.out.println(v.getSpeed());
//            }

            if(v instanceof ICheckSpeed){//属于我检测范围
                if(v.getSpeed()>100){
                    System.out.println("超速");
                }else{
                    System.out.println(v.getSpeed());
                }
            }else{
                System.out.println(v.getSpeed());
            }
        }
    }
}
